﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Showroom.DAL;
using MyGeneration.dOOdads;
using System.Collections.Specialized;
using System.Data;
using System.Data.SqlClient;

namespace Showroom.BLL
{
    public class Category : _Category
    {
        public static void DeleteByID(int ID)
        {
            TransactionMgr tx = TransactionMgr.ThreadTransactionMgr();
            try
            {
                tx.BeginTransaction();

                //Delete products
                CategoryProduct.DeleteAllProducts(ID);

                Category cat = new Category();
                cat.LoadByPrimaryKey(ID);
                cat.MarkAsDeleted();
                cat.Save();

                tx.CommitTransaction();
            }
            catch (Exception ex)
            {
                tx.RollbackTransaction();
                throw (ex);
            }
        }

        public static string GetListCategoryID(int CategoryID)
        {
            try
            {
                string sListID = "0123456789";
                Category c = new Category();
                c.proc_GetListCategory(CategoryID);
                for (int i = 0; i < c.RowCount; i++)
                {
                    sListID += c.s_ID + ",";
                    c.MoveNext();
                }
                return sListID.Trim(',');
            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }

        public virtual bool proc_GetListCategory(int CategoryID)
        {
            ListDictionary parameters = new ListDictionary();

            parameters.Add(new SqlParameter("@CategoryID", SqlDbType.Int, 0), CategoryID);

            return LoadFromSql("proc_GetListCategoryID", parameters);
        }
    }
}
